<!DOCTYPE html>

<html>
    <head>
        <title>prototype</title>
        <style scoped>
            body {
                width: 100%;
                height: 100%;
                margin: 0;
            }

            .box {
                background-color: violet;
                padding: 30px;
            }

            div {
                padding: 20px;
                border-bottom: 1px solid #aaa;
                cursor: pointer;
            }
        </style>
    </head>

    <body>
        <div class="box">prototype</div>
        <!-- <ol>
            <li>__proto__ === [[prototype]]</li>
            <li>任何对象都有这个属性</li>
            <li>本质是一个引用，指向对象的原型对象</li>
            <li>书面表达方式：[[prototype]]</li>
            <li>正经访问原型对象的方式：Object.getPrototypeOf(obj)</li>
            <li>正经设置原型对象属性：Object.setPrototypeOf()</li>
        </ol> -->

           <!-- <ol>
            <li>prototype</li>
            <li>原型对象</li>
            <li>通过obj.__proto__访问</li>
        </ol> -->

        <div id="dog" onclick="handleDog()">狗子</div>
        <div id="cat" onclick="handleCat()">猫咪</div>
    </body>

    <script>

        class Person {
            constructor(name) {
                this.name = name
            }

            personSay(language) {
                alert(`虽然你是${this.name}，但请说${language}！`)
            }
        }

        class Animal {
            constructor(name) {
                this.name = name
            }

            say(language) {
                alert(`你是真的${this.name}，请你说${language}！`)
            }
        }

        let dog = new Animal('狗子')
        // 把dog的原型对象指向Person的原型对象
        Object.setPrototypeOf(dog, Person.prototype)
        console.log('--dog--', dog)

        let cat = new Animal('猫咪')

        console.log(Animal.prototype === cat.__proto__) // true

        function handleDog() {
            dog.personSay('人语')
        }

        function handleCat() {
            cat.say('喵喵')
        }

        let obj = {
            name: 'obj'
        }
        console.log(obj)

        let obj1 = new Object()
        obj1.name = '111'
        // obj1.__proto__ === Object.prototype

        console.log(Object.prototype === obj.__proto__)
        // console.log(obj[[Prototype]][[Prototype]] === obj.__proto__)

    </script>
</html>